{block:style}
<style>
    .tabs-group .title {
        float: left;
        padding: 10px 0;
        width: 80px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        word-wrap: normal;
    }
    .tabs-group .content {
        list-style: none;
        padding: 0;
        margin: 0 0 0 80px;
    }
    .tabs-group .content > li {
        float: left;
        padding: 5px 12px;
        position: relative;
    }
    .tabs-group .content > li .show-down {
        position: absolute;
        right: 0;
        top: 10px;
        cursor: pointer;
        color: #7b7b7b;
    }
    .tabs-group .content > li > a {
        display: block;
        padding: 4px 5px;
        border: none;
        -webkit-border-radius: 4px;
        -webkit-background-clip: padding-box;
        -moz-border-radius: 4px;
        -moz-background-clip: padding;
        border-radius: 4px;
        background-clip: padding-box;
        color: #828a92;
        -webkit-transition: all 0.3s ease;
        -moz-transition: all 0.3s ease;
        -o-transition: all 0.3s ease;
        transition: all 0.3s ease;
    }
    .tabs-group .content > li.active > a, .tabs-group .content > li:hover > a {
        color: #34D0B6;
    }
    .tabs-group .content > li:hover > .dropdown-menu {
        display: block;
        margin-top: -2px;
    }
    .card-list .card img {
        height: 300px;
        object-fit: cover;
    }
    .card-list .card .card-title {
        width: 100%;
        height: 22px;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
        margin-bottom: 4px;
        font-size: 1.25em;
    }
    .card-list .card .card-text {
        width: 100%;
        height: 38px;
        overflow: hidden;
        color: #787878;
    }
    .card-list .card:hover {
        box-shadow: 0 0 2px rgba(52, 208, 182,.225), 0 1px 4px rgba(52, 208, 182,.3);
    }
    .user-img img {
        width: 100%;
        height: 100%;
        border-radius: 100%;
    }
    .footer-fa {
        color: #989da2;
    }
    .footer-fa span {
        margin-left: 2px;
    }
    .nav-pills .nav-link:not(.active):hover {
        color: #333333;
    }
    table th, table tr td {
        text-align: center;
        vertical-align: middle;
    }
    #template-pane .app-list .btn-uninstall {
        position: absolute;
        top: 0;
        right: 0;
    }
    .app-list .float-right span.dropdown-toggle {
        cursor: pointer;
    }
</style>
{/block:style}
<div class="card">
    <div class="card-header p-2">
        <ul class="nav nav-pills">
            {if has_rule('appcenter/index')}<li class="nav-item"><a class="nav-link active" href="{:url('/appcenter/index')}">{:lang("Local")}</a></li>{/if}
            {if has_rule('appcenter/online')}<li class="nav-item"><a class="nav-link" href="{:url('/appcenter/online')}">{:lang("Online")}</a></li>{/if}
        </ul>
    </div>
</div>
<div class="card card-primary card-tabs">
    <div class="card-header">
        <ul class="nav nav-tabs" id="custom-tabs-three-tab" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="pill" href="#template-pane" data-type="template">{:lang("Template")}</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="pill" href="#addon-pane" data-type="addon">{:lang("Addon")}</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="pill" href="#module-pane" data-type="module">{:lang("Module")}</a>
            </li>
        </ul>
    </div>
    <div class="card-body">
        <div class="tab-content" id="custom-tabs-three-tabContent">
            <div class="tab-pane fade active show" id="template-pane">
                <div class="clearfix">
                    <div class="float-left">
                        <div class="row">
                            <a class="btn btn-secondary" href="javascript:window.location.reload();" aria-label="Refresh" title="{:lang('Refresh')}">
                                <i class="fa fa-sync"></i>
                            </a>
                            &nbsp;&nbsp;
                            <ul class="nav nav-pills template-module">
                                <li class="nav-item"><a class="nav-link {if $active=='index'}active{/if}" data-value="index" href="{:url('/appcenter/index',['type'=>'template','module'=>'index'])}">{:lang("Foreground template")}</a></li>
                                <li class="nav-item"><a class="nav-link {if $active=='admin'}active{/if}" data-value="admin" href="{:url('/appcenter/index',['type'=>'template','module'=>'admin'])}">{:lang("Background template")}</a></li>
                                {volist name="module" id="vo"}
                                {if $vo['module']!='index' && $vo['module']!='admin'}
                                <li class="nav-item"><a class="nav-link {if $active==$vo['module']}active{/if}" data-value="{$key}" href="{:url('/appcenter/index',['type'=>'template','module'=>$vo['module']])}"><?php $title = \app\admin\model\App::where(['name'=>$vo['module']])->value('title');echo empty($title) ?  $vo['module'] : $title; ?></a></li>
                                {/if}
                                {/volist}
                            </ul>
                        </div>
                    </div>
                    <div class="float-right">
                        <div class="d-flex ">
                            <button type="button" class="btn btn-primary btn-upload" data-type="template"><i class="fa fa-download"></i>
                                {:lang("Local installation")}</button>
                            <input type="file" class="input-file1" style="display: none" name="files[]" accept="application/zip">
                        </div>
                    </div>
                </div>
                <div class="card-list">
                    <p></p>
                    <div class="app-list">

                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="addon-pane">
                <div class="clearfix">
                    <div class="float-left">
                        <a class="btn btn-secondary btn-refresh" href="#" data-type="addon" aria-label="Refresh" title="{:lang('Refresh')}">
                            <i class="fa fa-sync"></i>
                        </a>
                    </div>
                    <div class="float-right">
                        <div class="d-flex ">
                            <button type="button" class="btn btn-primary btn-upload" data-type="addon"><i class="fa fa-download"></i> {:lang("Local installation")}</button>
                            <input type="file" class="input-file1" style="display: none" name="files[]" accept="application/zip">
                        </div>
                    </div>
                </div>

                <div class="card-list">
                    <p></p>
                    <div class="row app-list"></div>
                </div>
            </div>
            <div class="tab-pane fade" id="module-pane">
                <div class="clearfix">
                    <div class="float-left">
                        <a class="btn btn-secondary btn-refresh" href="#" data-type="module" aria-label="Refresh" title="{:lang('Refresh')}">
                            <i class="fa fa-sync"></i>
                        </a>
                    </div>
                    <div class="float-right">
                        <div class="d-flex">
                            <button type="button" class="btn btn-primary btn-upload" data-type="module"><i class="fa fa-download"></i> {:lang("Local installation")}</button>
                            <input type="file" class="input-file1" style="display: none" name="files[]" accept="application/zip">
                        </div>
                    </div>
                </div>

                <div class="card-list">
                    <p></p>
                    <div class="row app-list"></div>
                </div>
            </div>
        </div>
    </div>
</div>

{block:script}
<script>
    require(['jquery','bootstrap','layer','jquery-fileupload'], function ($,undefined,Layer) {
        /**
         * 获取插件列表
         */
        function getAddonList(type)
        {
            type = (type || $('#custom-tabs-three-tab').find('.nav-link.active').data('type'));
            Util.ajax({
                url:'{:url("/Appcenter/index")}',
                data: {type: type,module: $('.template-module').find('.active').data('value')}
            }, '', function (data) {
                $('#'+type+'-pane .app-list').html(data.html);
                $('[data-toggle="tooltip"]').tooltip();
            });
        }

        $('.btn-refresh').on('click',function (e) {
            getAddonList($(this).data('type'));
        })

        // 类型切换
        $('#custom-tabs-three-tab').on('click', 'a', function(e) {
            e.preventDefault();
            getAddonList($(this).data('type'));
        });

        // 卸载
        $(document).on('click', '.btn-uninstall', function (e) {
            var that = this;
            Layer.confirm('{:lang("Are you sure to uninstall? The file will also be deleted.")}', {
                btn: ['{:lang("Uninstall")}','{:lang("Cancel")}'],
                icon: 5
            }, function(){
                var obj = {
                    name: $(that).data('name'),
                    type: $(that).data('type'),
                    module: $(that).data('module')
                }
                Util.ajax({
                    url:'{:url("/Appcenter/uninstall")}',
                    data: obj
                }, '', function (data) {
                    Layer.msg("{:lang('Operation completed')}",{time: 1000,icon:1},function () {
                        getAddonList('');
                    });
                },function (data) {
                    Layer.alert(data.msg);
                    return false;
                });
            }, function(){
            });
        });

        /**
         * 更新
         */
        $(document).on('click', '.btn-upgrade', function (e) {
            e.preventDefault();
            var version = $(this).data('version');
            var obj = {name:$(this).data('name')};
            if (typeof version !=='undefined') {
                obj.version = version;
            }

            Util.ajax({
                url:'{:url("/Appcenter/upgrade")}',
                data: obj
            }, '', function (data) {
                Layer.msg("{:lang('Operation completed')}",{time: 1000},function () {
                    getAddonList('');
                });
                return false;
            },function (data) {
                Layer.alert(data.msg);
                return false;
            });
        });

        // 启用、禁用
        $(document).on('change', '.custom-control-input', function (e) {
            e.preventDefault();

            let value = $(this).val();
            value = value==1?-1:1;

            Util.ajax({
                url:'{:url("/Appcenter/enable")}',
                data: {value:value,type:$('#custom-tabs-three-tab').find('.nav-link.active').data('type'),name:$(this).data('name')}
            }, '', function (data) {
                Layer.msg("{:lang('Operation completed')}",{time: 1000},function () {
                    getAddonList('');
                });
            },function (data) {
                Layer.alert(data.msg);
                return false;
            });
        });

        // 安装本地
        $(document).on('click', '.btn-install-db', function (e) {
            e.preventDefault();
            var obj = {name:$(this).data('name'),type:$(this).data('type')};

            var module  = $(this).data('module');
            if (typeof module  !=='undefined') {
                obj.module = module;
            }

            Util.ajax({
                url:'{:url("/Appcenter/installDb")}',
                data: obj
            }, '', function (data) {
                layer.msg("{:lang("Operation completed")}",{time: 1000},function () {
                    getAddonList('');
                });
                return false;
            },function (data) {
                layer.alert(data.msg);
                return false;
            });
        });


        /**
         * 离线上传安装
         */
        $('.btn-upload').click(function (e) {
            e.preventDefault();
            var type = $(this).data('type');
            var option = {
                url: "{:url('/appcenter/local')}?type="+type,
                type: 'POST',
                dataType: 'json', // 服务器返回的数据类型
                autoUpload: true, // 选择文件后自动上传
                mimetype: 'application/zip,application/x-zip-compressed',  // 文件类型
                size: Config.file_size,
                singleFileUploads: false,
                fileNum: 1,
                add: function (e, data) {
                    let arr = option.mimetype.split(',');
                    if (data.originalFiles.length > option.fileNum) {
                        Layer.msg(lang('Only %s file can be uploaded at a time!',[option['fileNum']]));
                        return false;
                    }
                    for (let idx in data.originalFiles) {
                        var type = data.originalFiles[idx]['type'];
                        if (option.mimetype.indexOf("/*") !== -1) {
                            type = type.split('/');
                            type[1] = '*';
                            type = type.join('/');
                        }
                        if (option.mimetype!='*' && 0>$.inArray(type, arr)) {
                            Layer.msg(lang('Unsupported file suffix'));
                            return false;
                        }

                        //文件大小判断
                        if(data.originalFiles[idx].size > option.size) {
                            Layer.msg(lang('Please upload a leaflet that does not exceed %s', (option.size/1024/1024).toFixed(2)+'M'));
                            return false;
                        }
                    }

                    data.submit();
                }
            };
            $('.input-file1').fileupload(option).on('fileuploaddone', function (e, data) {
                if (data.result.code==200) {
                    Layer.msg("{:lang('Operation completed')}",{time:1000}, function (e) {
                        getAddonList('');
                    });
                } else {
                    Layer.alert(data.result.msg);
                }
            });

            $(this).next().click();
        });

        getAddonList('');
    })
</script>
{/block:script}